package cn.how2j.springcloud.service;

import java.util.List;

import cn.how2j.springcloud.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import cn.how2j.springcloud.client.ProductClientFeign;
import cn.how2j.springcloud.pojo.Product;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service

public class ProductService {
    @Autowired
    ProductClientFeign productClientFeign;

    @Autowired
    private UserService userService;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public List<Product> listProducts() {
        String s = userService.Sel(111).toString();
        System.out.println(s);

        //根据真实名字查询密码
        List<String> ldj = userService.select("ldj");
        System.out.println(ldj);

        //插入数据
        User user = new User();
        user.setUserName("111");
        user.setPassWord("22" + System.currentTimeMillis());
        user.setRealName("ldj");
        userService.insert(user);

        //有try catch 上面的insert不会回滚
//        List<Product> products = null;
//        try {
//            products = productClientFeign.listProdcuts();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

//        //没有try catch 上面的insert会回滚
        List<Product> products = null;
        products = productClientFeign.listProdcuts();
        return products;

    }
}
